<meta charset="utf-8">
<script>
    var amount = parseInt(prompt("请输入考试科目的数量："));
    if(amount<=0){
        alert("请输入正确的考试科目数量：");
    }else{
        var sum = 0;
        for(var i=1;i<=amount;i++){
            var flag;
            var core = parseInt(prompt("请输入第"+i+"门科目的成绩："));            
            if(core<0){
                alert("请输入合法的成绩：");
                flag = false;
                break;
            }else{
                flag = true;
                sum = sum+core;
            }             
        }
        if(flag){
            alert(amount+"门科目的总成绩是："+sum);
        }
    }  
</script>